#include "StdAfx.h"
#include "VoiceTalkStateConnected.h"
#include "TalkObject.h"
#include "AnalogTrunk.h"
#include "VoiceTalkObject.h"
#include "TinyServerDefine.h"

namespace TalkProcess{

CVoiceTalkStateConnected::CVoiceTalkStateConnected(void)
{
}

CVoiceTalkStateConnected::~CVoiceTalkStateConnected(void)
{
}
void CVoiceTalkStateConnected::ProcessReceivedMsg(CTinyMsg& inMsg,CTinyMsg& OutMsg)
{
	if(inMsg.getMsgIndex() == VOICECARD_ACTION)
	{
		switch (inMsg.getMsgItem())
		{
		case VOICECARD_CONNECTED:
			{
				//if right, prepare to change state to connected;
				HAL::CAnalogTrunk* trunk = g_DevicePool.GetTrunkByID((dynamic_cast<CVoiceTalkObject*>(this->talkObjectHandle))->calledID);
				if(trunk != NULL)
				{
					string moudleType,deviceID,callerID,deviceType;
					inMsg.getDefaultParamByIndex(VOICECARD_CONNECTED_MODULENAME,moudleType);
					inMsg.getDefaultParamByIndex(VOICECARD_CONNECTED_DEVICEID,deviceID);
					inMsg.getDefaultParamByIndex(VOICECARD_CONNECTED_DEVICETYPE,deviceType);
					g_FlowPool.StartFlow("",deviceID,talkObjectHandle->GetTalkID());

				}

				HAL::CAnalogPhone* phone = g_DevicePool.GetExtensionByID((dynamic_cast<CVoiceTalkObject*>(this->talkObjectHandle))->calledID);
				if(phone != NULL)
				{
					//phone->pickup();
				}

			}break;
		default:
			{
				g_FlowPool.ProcessReceivedMsg(inMsg,OutMsg);
			}
			break;
		}
	}
}
}